package com.huifaapp.mall.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.huifaapp.mall.R;
import com.huifaapp.mall.activity.DetailsofPaymentActivity;
import com.huifaapp.mall.afinal.Constants;
import com.huifaapp.mall.bean.CouponListBean;
import com.huifaapp.mall.bean.GoodsListBean;
import com.huifaapp.mall.uitils.Contig;
import com.huifaapp.mall.uitils.UtilsImage;
import com.huifaapp.mall.view.PosterWin;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;


/**
 *
* @ClassName: IntroductionPageAdapter
* @Description: TODO(引导页)
* @author lijs
* @date 2016年5月11日 下午1:34:37
*
 */
public class DetailsofPaymenthongbaoAdapter {

	public static class ViewHolder {
		TextView tv_poster_win_hb_price;
		TextView tv_poster_win_hb_mainyong;
		TextView tv_poster_win_hb_qixiang;
		ImageView iv_poster_win_hb_lijilingqu;
		TextView tv_poster_win_hb_price_d;
		TextView tv_poster_win_hb_mainyong_d;
		TextView tv_poster_win_hb_qixiang_d;
		LinearLayout ll_poster_win_hongbao_lijilingqu;
		LinearLayout ll_poster_win_hongbao_weimianzu;
		public ViewHolder(View convertView) {

			tv_poster_win_hb_price= (TextView) convertView.findViewById(R.id.tv_poster_win_hb_price);
			tv_poster_win_hb_mainyong= (TextView) convertView.findViewById(R.id.tv_poster_win_hb_mainyong);
			tv_poster_win_hb_qixiang= (TextView) convertView.findViewById(R.id.tv_poster_win_hb_qixiang);
			iv_poster_win_hb_lijilingqu= (ImageView) convertView.findViewById(R.id.iv_poster_win_hb_lijilingqu);
			ll_poster_win_hongbao_lijilingqu= (LinearLayout) convertView.findViewById(R.id.ll_poster_win_hongbao_lijilingqu);
			ll_poster_win_hongbao_weimianzu= (LinearLayout) convertView.findViewById(R.id.ll_poster_win_hongbao_weimianzu);
			tv_poster_win_hb_price_d= (TextView) convertView.findViewById(R.id.tv_poster_win_hb_price_d);
			tv_poster_win_hb_mainyong_d= (TextView) convertView.findViewById(R.id.tv_poster_win_hb_mainyong_d);
			tv_poster_win_hb_qixiang_d= (TextView) convertView.findViewById(R.id.tv_poster_win_hb_qixiang_d);

		}
		public void setdate(final Context context, final CouponListBean bean){
			tv_poster_win_hb_price.setText(bean.getAmount()+"");
			tv_poster_win_hb_mainyong.setText("满"+bean.getUseCond()+"元可用");
			tv_poster_win_hb_qixiang.setText("使用期限："+bean.getStartTime()+"—"+bean.getEndTime());
			tv_poster_win_hb_price_d.setText(bean.getAmount()+"");
			tv_poster_win_hb_mainyong_d.setText("满"+bean.getUseCond()+"元可用");
			tv_poster_win_hb_qixiang_d.setText("使用期限："+bean.getStartTime()+"—"+bean.getEndTime());

//				double a = Double.valueOf(Contig.datatotal);
				if (Contig.datatotal >= bean.getUseCond()) {
					Log.e("付",Contig.datatotal +"  2s    "+bean.getUseCond());
					ll_poster_win_hongbao_lijilingqu.setVisibility(View.VISIBLE);
					ll_poster_win_hongbao_weimianzu.setVisibility(View.GONE);
				} else {
					Log.e("付",Contig.datatotal +"   22s   "+bean.getUseCond());
					ll_poster_win_hongbao_lijilingqu.setVisibility(View.GONE);
					ll_poster_win_hongbao_weimianzu.setVisibility(View.VISIBLE);
				}

			iv_poster_win_hb_lijilingqu.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					Contig.couponId=bean.getId();
					Toast.makeText(context,bean.getId()+"=========="+Contig.couponId,Toast.LENGTH_SHORT).show();
					Log.e("数据","Contig.couponId=-============"+Contig.couponId);
                    DetailsofPaymentActivity.mPopposter.dismiss();
					DetailsofPaymentActivity.Order(context);
//					DetailsofPaymentActivity.submitOrder(context);
					DetailsofPaymentActivity.tv_PayDetails_couponAmount.setText("¥"+bean.getAmount());
					try {
//						double a = Double.valueOf(Contig.datatotal);
						if (Contig.datatotal >= bean.getUseCond()) {
							Log.e("数据",Contig.datatotal+"  2红包券   "+bean.getUseCond());
							ll_poster_win_hongbao_lijilingqu.setVisibility(View.VISIBLE);
							ll_poster_win_hongbao_weimianzu.setVisibility(View.GONE);
						} else {
							Toast.makeText(context,Contig.datatotal +"  222红包券    "+bean.getUseCond(),Toast.LENGTH_SHORT).show();
							ll_poster_win_hongbao_lijilingqu.setVisibility(View.GONE);
							ll_poster_win_hongbao_weimianzu.setVisibility(View.VISIBLE);
						}
					}catch (Exception e){
						Log.e("Exception",e.getMessage());
					}
				}
		 	});
		}

	}
}